﻿using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Utilities.Encoders;
using System.Text;

namespace PmSoft.Utilities.Sm3;

/// <summary>
/// 国密3加密工具类
/// </summary>
public static class SM3Util
{
    public static string Encrypt(string data)
    {
        byte[] input = Encoding.UTF8.GetBytes(data);

        IDigest digest = new SM3Digest();
        byte[] hashBytes = new byte[digest.GetDigestSize()];

        digest.BlockUpdate(input, 0, input.Length);
        digest.DoFinal(hashBytes, 0);

        string hashString = Hex.ToHexString(hashBytes);

        return hashString;
    }

}
